package com.huanong.interceptors;

import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdminInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("admin") || cookie.getName().equals("user")) {
//                System.out.println("登录是否成功" + cookie.getName());
                if (cookie.getValue() != null) {
                    return true;
                } else {
                    return false;
                }
            }
        }
        return false;
    }
}
